<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/23
 * Time: 11:56
 * function:用于将yg_goods(商品表)中cost_price(成本价)中数据同步到yg_order(订单表)中的order_costamount(成本价)
 */
exit;
$ip = "120.76.200.79";
$username = "yunguo";
$pwd = "yg201610";
$data_name = "yunguo";
$con = @mysql_connect($ip,$username,$pwd);
if (!$con)
{
    die('Could not connect: ' . @mysql_error());
}
@mysql_select_db($data_name);

$u_sql = "update yg_order set order_costamount = 0";
$update = @mysql_query($u_sql,$con);
if(!$update){
    die('Could not update yg_order');
}

$sql = "select g.cost_price,o.id,og.goods_id from yg_order as o left join yg_order_goods as og on o.id = og.order_id left join yg_goods as g on g.id = og.goods_id";

$result = @mysql_query($sql,$con);
while($row=@mysql_fetch_assoc($result))
{
    $data[] = $row;
}
foreach($data as $k=>$v){
    $sqls = "update yg_order set order_costamount=order_costamount+{$data[$k]['cost_price']} where id={$data[$k]['id']}";
    $res = @mysql_query($sqls,$con);
}



